using System.Diagnostics;

namespace AzureContrib.WindowsAzure.Diagnostics
{
	/// <summary>
	/// Extension methods on <see cref="ITraceSwitchProvider"/>.
	/// </summary>
	public static class TraceControlExtensions
	{
		/// <summary>
		/// Is tracing set to <see cref="TraceLevel.Off"/> for this <see cref="ITraceSwitchable"/>?
		/// </summary>
		/// <returns>True if tracing is enabled.</returns>
		public static bool Disabled(this ITraceSwitchProvider traceSwitchProvider, ITraceSwitchable traceSwitchable)
		{
			return traceSwitchProvider.GetSwitch(traceSwitchable).Level == TraceLevel.Off;
		}

		/// <summary>
		/// Is tracing at the <see cref="TraceLevel.Verbose"/> level enabled for this <see cref="ITraceSwitchable"/>?
		/// </summary>
		/// <returns>True if tracing is enabled.</returns>
		public static bool VerboseEnabled(this ITraceSwitchProvider traceSwitchProvider, ITraceSwitchable traceSwitchable)
		{
			return traceSwitchProvider.GetSwitch(traceSwitchable).TraceVerbose;
		}

		/// <summary>
		/// Is tracing at the <see cref="TraceLevel.Info"/> level enabled for this <see cref="ITraceSwitchable"/>?
		/// </summary>
		/// <returns>True if tracing is enabled.</returns>
		public static bool InformationEnabled(this ITraceSwitchProvider traceSwitchProvider, ITraceSwitchable traceSwitchable)
		{
			return traceSwitchProvider.GetSwitch(traceSwitchable).TraceInfo;
		}

		/// <summary>
		/// Is tracing at the <see cref="TraceLevel.Warning"/> level enabled for this <see cref="ITraceSwitchable"/>?
		/// </summary>
		/// <returns>True if tracing is enabled.</returns>
		public static bool WarningEnabled(this ITraceSwitchProvider traceSwitchProvider, ITraceSwitchable traceSwitchable)
		{
			return traceSwitchProvider.GetSwitch(traceSwitchable).TraceWarning;
		}

		/// <summary>
		/// Is tracing at the <see cref="TraceLevel.Error"/> level enabled for this <see cref="ITraceSwitchable"/>?
		/// </summary>
		/// <returns>True if tracing is enabled.</returns>
		public static bool ErrorEnabled(this ITraceSwitchProvider traceSwitchProvider, ITraceSwitchable traceSwitchable)
		{
			return traceSwitchProvider.GetSwitch(traceSwitchable).TraceError;
		}
	}
}